﻿using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
using Wicresoft.NRemedy.VS10Addin.UI;

namespace Wicresoft.NRemedy.VS10Addin
{
    public class CommandHandler
    {
        public static void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled, 
            DTE2 _applicationObject,
            AddIn _addin)
        {
            Handled = false;
            if (ExecuteOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if (CmdName == "Wicresoft.NRemedy.VS10Addin.Connect." + Const.Create_Remedy_Model_Command_Name)
                {
                    if (_applicationObject.SelectedItems.Count > 1)
                    {
                        MessageBox.Show("Mutipule items selected.You can only select one item before.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (_applicationObject.SelectedItems.Count == 0)
                    {
                        MessageBox.Show("Missing item selected.You can only select one item before.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        RemedyModelAdd addform = new RemedyModelAdd(_applicationObject, _addin);
                        addform.ShowDialog();
                    }
                }
            }

        }

        public static void QueryStatus(string CmdName, vsCommandStatusTextWanted NeededText, ref vsCommandStatus StatusOption, ref object CommandText)
        {
            if (NeededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
            {
                if (CmdName == "Wicresoft.NRemedy.VS10Addin.Connect." +Const.Create_Remedy_Model_Command_Name)
                {
                    StatusOption = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
            }
        }
    }
}
